package com.medi.web.controller.business;

import java.util.List;

import com.medi.business.domain.vo.DataRelationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.medi.common.annotation.Log;
import com.medi.common.core.controller.BaseController;
import com.medi.common.core.domain.AjaxResult;
import com.medi.common.enums.BusinessType;
import com.medi.business.domain.DataRelation;
import com.medi.business.service.IDataRelationService;
import com.medi.common.core.page.TableDataInfo;

/**
 * 数据权限关系Controller
 * 
 * @author medi
 * @date 2024-09-13
 */
@Api(tags = "后台管理-数据权限关系管理")
@RestController
@RequestMapping("/business/datarelation")
public class DataRelationController extends BaseController
{
    @Autowired
    private IDataRelationService dataRelationService;

    /**
     * 查询数据权限关系列表
     */
    @ApiOperation("查询需要角色数据权限控制接口列表")
    @GetMapping("/list")
    public TableDataInfo list(DataRelation dataRelation)
    {
        startPage();
        List<DataRelationVo> list = dataRelationService.selectDataRelationVoList(dataRelation);
        return getDataTable(list);
    }

    /**
     * 获取数据权限关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:datarelation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(dataRelationService.selectDataRelationById(id));
    }

    /**
     * 新增数据权限关系
     */
    @PreAuthorize("@ss.hasPermi('business:datarelation:add')")
    @Log(title = "数据权限关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataRelation dataRelation)
    {
        return toAjax(dataRelationService.insertDataRelation(dataRelation));
    }

    /**
     * 修改数据权限关系
     */
    @PreAuthorize("@ss.hasPermi('business:datarelation:edit')")
    @Log(title = "数据权限关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataRelation dataRelation)
    {
        return toAjax(dataRelationService.updateDataRelation(dataRelation));
    }

    /**
     * 删除数据权限关系
     */
    @PreAuthorize("@ss.hasPermi('business:datarelation:remove')")
    @Log(title = "数据权限关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dataRelationService.deleteDataRelationByIds(ids));
    }
}
